<template>
	<view class="my-activeity">
		<bs-navbar title='我的活动'></bs-navbar>
		<u-sticky :offset-top='navHeight'>
			<view class="sticky">
				<u-tabs active-color='#0050A5' inactive-color='#9A9A9A' :list="list" :is-scroll="false" :current="current" @change="change"></u-tabs>
			</view>
		</u-sticky>

		<bs-gap top="0" bottom="0"></bs-gap>
		<view class="my-activeity-padding">
			<bsList :showEmpty='current!=1' onMsg='暂无活动' @handNavDetails='handNavDetails' :props='props' :status='status' :list='activList'
			 :page='page'></bsList>
		</view>
		<view class="no-cear" v-if="current==1&&activList.length==0">
			请使用电脑登录中装协官网，在首页创建活动。创建成功后，您的活动将收录进中装协系统中，并可被用户看到。<br>
			<view class="mt-40">
				官网链接：www.cbda1984.com
			</view>
			<image class="no-img" :src="imgUrl+'cjhd.png'" mode=""></image>
		</view>
		<u-back-top :scroll-top="scrollTop"></u-back-top>
	</view>
</template>

<script>
	import bsList from '@/components/bs-list/bs-list.vue'
	export default {
		components: {
			bsList
		},
		data() {
			return {
				imgUrl: this.configImgUrl,
				scrollTop: 0,
				activList: [],
				props: {
					title233: 'title',
					name233: 'name',
				},
				navHeight: this.CustomBar * 2,
				page: 0,
				pages: 0,
				status: 'nomore',
				paging: {
					page: 1,
					pageSize: 10,
				},
				list: [{
					name: '参加的活动'
				}, {
					name: '创建的活动'
				}],
				current: 0
			};
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		async onReachBottom() {
			await this.getMore()
		},
		onLoad() {
			this.init()
		},
		methods: {
			async getMore() {
				if (this.pages == this.paging.page) {
					this.status = 'nomore';
					return
				}
				this.status = 'loading';
				this.paging.page = ++this.paging.page;
				let activList = []
				if (this.current == 0) {
					activList = await this.$u.api.selectParticipateInActivities(this.paging)
				} else {
					activList = await this.$u.api.userFindWaitAuditActivity(this.paging)
				}
				this.pages = activList.pages
				this.activList = this.activList.concat(activList.list)
				this.status = 'loadmore';
			},
			//我参加的
			async init() {
				let res = await this.$u.api.selectParticipateInActivities(this.paging)
				this.pages = res.pages
				this.activList = res.list
				console.log(this.activList)
			},
			//我创建的
			async setInit() {
				let res = await this.$u.api.userFindWaitAuditActivity(this.paging)
				this.pages = res.pages
				this.activList = res.list
				console.log(this.activList)
			},
			async change(index) {

				this.paging.page = 1
				if (index === 0) {
					await this.init()
				} else {
					await this.setInit()
				}
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 300
				});
				this.current = index;
			},
			handNavDetails(item) {
				if (this.current == 1 && item.status == '8' || item.status == '4') {
					uni.navigateTo({
						url: '/pages/my/myActiveity/setActDetails/setActDetails?activityId=' + item.activityId
					})
				} else {
					uni.navigateTo({
						url: '/pages/my/myActiveity/joinActDetails/joinActDetails?activityId=' + item.activityId
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.no-cear {
		padding: 30rpx;

		.no-img {
			width: 100%;
			height: 1160rpx;
			margin-top: 76rpx;
		}
	}

	.my-activeity {
		.my-activeity-padding {
			padding: 0 30rpx;
		}
	}
</style>
